import {
  FundProjectionScreenOutlined,
  DesktopOutlined,
  ShoppingOutlined,
  CarryOutOutlined,
  CreditCardOutlined,
  CrownOutlined,
  SendOutlined,
  NotificationOutlined,
  LineChartOutlined,
  TransactionOutlined,
  SettingOutlined,
} from '@ant-design/icons';
import withRetry from '../components/ErrorBoundary/withRetry'

const menu = [
  {
    key: '/general',
    icon: <FundProjectionScreenOutlined />,
    label: '概况',
    title: '概况',
    component: withRetry(() => import('../views/GeneralView')),
  },
  {
    key: '/facility',
    icon: <DesktopOutlined />,
    label: '设备',
    title: '设备',
    children: [
      {
        key: '/facility/list',
        label: '设备列表',
        title: '设备列表',
        component: withRetry(() => import('../views/FacilityView/FacilityList')),
      },
    ],
  },
  {
    key: '/wares',
    icon: <ShoppingOutlined />,
    label: '商品',
    title: '商品',
    children: [
      {
        key: '/wares/store',
        label: '商品库',
        title: '商品库',
        component: withRetry(() => import('../views/WareView/WareStore')),
      },
      {
        key: '/wares/price',
        label: '价格模板',
        title: '价格模板',
        component: withRetry(() => import('../views/WareView/WarePrice')),
      },
    ],
  },
  {
    key: '/order',
    icon: <CarryOutOutlined />,
    label: '订单',
    title: '订单',
    children: [
      {
        key: '/order/market',
        label: '销售订单',
        title: '销售订单',
        component: withRetry(() => import('../views/OrderView/OrderMarket')),
      },
      {
        key: '/order/error',
        label: '异常订单',
        title: '异常订单',
        component: withRetry(() => import('../views/OrderView/OrderError')),
      },
      {
        key: '/order/refund',
        label: '退款订单',
        title: '退款订单',
        component: withRetry(() => import('../views/OrderView/OrderRefund')),
      },
    ],
  },
  {
    key: '/storage',
    icon: <CreditCardOutlined />,
    label: '仓储',
    title: '仓储',
    children: [
      {
        key: '/storage/check',
        label: '盘点单',
        title: '盘点单',
        component: withRetry(() => import('../views/StorageView/StorageCheck')),
      },
      {
        key: '/storage/replenishment',
        label: '补货单',
        title: '补货单',
        component: withRetry(() => import('../views/StorageView/StorageReplenishment')),
      },
      {
        key: '/storage/inventory',
        label: '商品库存',
        title: '商品库存',
        component: withRetry(() => import('../views/StorageView/StorageInventory')),
      },
    ],
  },
  {
    key: '/member',
    icon: <CrownOutlined />,
    label: '会员',
    title: '会员',
    children: [
      {
        key: '/member/all',
        label: '所有会员',
        title: '所有会员',
        component: withRetry(() => import('../views/MemberView/MemberAll')),
      },
      {
        key: '/member/group',
        label: '会员分群',
        title: '会员分群',
        component: withRetry(() => import('../views/MemberView/MemberGroup')),
      },
      {
        key: '/member/event',
        label: '标签管理',
        title: '标签管理',
        component: withRetry(() => import('../views/MemberView/MemberEvent')),
      },
      {
        key: '/member/black',
        label: '黑名单会员',
        title: '黑名单会员',
        component: withRetry(() => import('../views/MemberView/MemberBlack')),
      },
    ],
  },
  {
    key: '/marketing',
    icon: <SendOutlined />,
    label: '营销',
    title: '营销',
    children: [
      {
        key: '/marketing/use',
        label: '营销应用',
        title: '营销应用',
        component: withRetry(() => import('../views/MarketingView/MarketingUse')),
      },
    ],
  },
  {
    key: '/advertising',
    icon: <NotificationOutlined />,
    label: '广告',
    title: '广告',
    children: [
      {
        key: '/advertising/fodder',
        label: '广告素材',
        title: '广告素材',
        component: withRetry(() => import('../views/AdvertisingView/AdvertisingFodder')),
      },
      {
        key: '/advertising/tactics',
        label: '策略管理',
        title: '策略管理',
        component: withRetry(() => import('../views/AdvertisingView/AdvertisingTactics')),
      },
    ],
  },
  {
    key: '/data',
    icon: <LineChartOutlined />,
    label: '数据',
    title: '数据',
    children: [
      {
        key: '/data/cabinet',
        label: '柜机销售统计',
        title: '柜机销售统计',
        component: withRetry(() => import('../views/DataView/DataCabinet')),
      },
      {
        key: '/data/ware',
        label: '商品销售统计',
        title: '商品销售统计',
        component: withRetry(() => import('../views/DataView/DataWare')),
      },
    ],
  },
  {
    key: '/finance',
    icon: <TransactionOutlined />,
    label: '财务',
    title: '财务',
    children: [
      {
        key: '/finance/clearance',
        label: '结算明细',
        title: '结算明细',
        component: withRetry(() => import('../views/FinanceView/FinanceClearance')),
      },
      {
        key: '/finance/deal',
        label: '交易明细',
        title: '交易明细',
        component: withRetry(() => import('../views/FinanceView/FinanceDeal')),
      },
      {
        key: '/finance/account',
        label: '账户明细',
        title: '账户明细',
        component: withRetry(() => import('../views/FinanceView/FinanceAccount')),
      },
    ],
  },
  {
    key: '/set',
    icon: <SettingOutlined />,
    label: '设置',
    title: '设置',
    children: [
      {
        key: '/set/person',
        label: '商户管理',
        title: '商户管理',
        type: 'group',
        children: [
          {
            key: '/set/person/messages',
            label: '商户信息',
            title: '商户信息',
            component: withRetry(() => import('../views/SetView/SetPerson/SetPersonMessages')),
          },
          {
            key: '/set/person/authentication',
            label: '商户认证',
            title: '商户认证',
            component: withRetry(() => import('../views/SetView/SetPerson/SetPersonAuthentication')),
          },
        ],
      },
      {
        key: '/set/root',
        label: '账号权限',
        title: '账号权限',
        type: 'group',
        children: [
          {
            key: '/set/root/id',
            label: '账号管理',
            title: '账号管理',
            component: withRetry(() => import('../views/SetView/SetRoot/SetRootId')),
          },
          {
            key: '/set/root/role',
            label: '角色管理',
            title: '角色管理',
            component: withRetry(() => import('../views/SetView/SetRoot/SetRootRole')),
          },
          {
            key: '/set/root/log',
            label: '操作日志',
            title: '操作日志',
            component: withRetry(() => import('../views/SetView/SetRoot/SetRootLog')),
          },
        ],
      },
    ],
  },
]

export const findOuterKey = (key) => {
  for (let i = 0; i < menu.length; i++) {
    if (!menu[i].children) continue
    for (let j = 0; j < menu[i].children.length; j++) {
      if (menu[i].children[j].key === key) {
        return [menu[i].key]
      } else if (menu[i].children[j].children) {
        for (let k = 0; k < menu[i].children[j].children.length; k++) {
          if (menu[i].children[j].children[k].key === key) {
            return [menu[i].key]
          }
        }
      }
    }
  }
  return []
}
export default menu;
